Match ‘ab’ followed by two to three chars¶
pattern = ‘ab{2,3}?’
Write a python program that matches a string
that has an a followed by two to three ‘b’.
import re
def text_match(S):
pattern = 'ab{2,3}?'
if re.search(pattern, S):
return 'Found a match!'
else:
return 'Not matched!'
# test
print(text_match("ab")) # Not matched!
print(text_match("aabbbbbc")) # Found a match!